#include "stdafx.h"
#include "RasterizerState.h"

namespace Reign
{namespace Video
{namespace D3D10
{
	#pragma region Constructors
	RasterizerState::RasterizerState(DisposableI^ parent, RasterizerStateDescI^ desc)
	: Disposable(parent)
	{
		null();
		try
		{
			video = parent->FindParentOrSelfWithException<Video^>();

			ID3D10RasterizerState* rasterizerStateTEMP;
			RasterizerStateDesc^ descTEMP = (RasterizerStateDesc^)desc;
			if (FAILED(video->Device->CreateRasterizerState(descTEMP->Desc, &rasterizerStateTEMP)))
			{
				Debug::ThrowError(L"RasterizerState", L"Failed to create RasterizerState");
			}
			rasterizerState =  rasterizerStateTEMP;
		}
		catch (Exception^ ex)
		{
			delete this;
			throw ex;
		}
	}

	RasterizerState::~RasterizerState()
	{
		disposeChilderen();
		if (rasterizerState) rasterizerState->Release();
		null();
	}

	void RasterizerState::null()
	{
		rasterizerState = 0;
	}
	#pragma endregion
	
	#pragma region Methods
	void RasterizerState::Enable()
	{
		video->Device->RSSetState(rasterizerState);
	}
	#pragma endregion
}
}
}